#ifndef GPU_NEWTONRAPHSON_H
#define GPU_NEWTONRAPHSON_H

#include <NewtonRaphson.h>
#include "GPU_IncrementalIntegrator.h"
#include <memory>

/**
 * GPU-accelerated Newton-Raphson algorithm for OpenSees
 * Integrates GPU-accelerated formUnbalance with Newton-Raphson solution
 */
class GPU_NewtonRaphson : public NewtonRaphson {
public:
    GPU_NewtonRaphson(int maxElements = 50000, int maxDOFs = 100000, int maxNodes = 50000);
    GPU_NewtonRaphson(ConvergenceTest& theTest, int maxElements = 50000, int maxDOFs = 100000, int maxNodes = 50000);
    virtual ~GPU_NewtonRaphson();

    // Override solveCurrentStep to use GPU-accelerated integrator
    virtual int solveCurrentStep(void) override;
    
    // Configuration methods
    void enableGPU(bool enable);
    void enableProfiling(bool enable);
    void setMaxProblemSize(int maxElements, int maxDOFs, int maxNodes);
    
    // Performance monitoring
    void printPerformanceStats() const;
    
    // Method information
    virtual int sendSelf(int commitTag, Channel &theChannel) override;
    virtual int recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker) override;
    virtual void Print(OPS_Stream &s, int flag = 0) override;

protected:
    // GPU-accelerated integrator
    std::shared_ptr<GPU_IncrementalIntegrator> gpuIntegrator;
    
    // Configuration
    bool gpuEnabled;
    bool profilingEnabled;
    
    // Problem size limits
    int maxElements, maxDOFs, maxNodes;
    
    // Performance tracking
    mutable int totalIterations;
    mutable double totalSolveTime;
    mutable double totalFormUnbalanceTime;
    mutable double totalLinearSolveTime;
    
private:
    void initialize();
    void recordPerformance(double solveTime, double formUnbalanceTime, double linearSolveTime, int iterations);
};

#endif // GPU_NEWTONRAPHSON_H